package com.tedu.bill.demo2;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.UUID;

/**
 * Author：毕龙
 * Date: 2024/5/26 15:53
 */
public class TestFileCopy1 {
    public static void main(String[] args) throws IOException {

        File file = new File("day14/src/DeadLock.mp4");
        //创建输入流
        FileInputStream fis = new FileInputStream(file);

        System.out.println(file.length());


        //数组
        byte[] bytes = new byte[1024*1024*50];
        //该文件刚好能放在数组中
        if(file.length() <= bytes.length){
            //创建输出流
            FileOutputStream fos = new FileOutputStream("day14/src/com/tedu/bill/demo2/"+ UUID.randomUUID().toString()+".mp4");
            int len = bytes.length;
            while ((len=fis.read(bytes,0,len))!= -1){
                fos.write(bytes,0,len);
            }
        }else{

            int len = bytes.length;
            while ((len=fis.read(bytes,0,len))!= -1){
                //创建输出流
                FileOutputStream fos = new FileOutputStream("day14/src/com/tedu/bill/demo2/"+ UUID.randomUUID().toString()+".mp4");
                fos.write(bytes,0,len);
            }
        }


        //释放流

        fis.close();
    }
}
